package com.lyd.management.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.util.SaResult;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lyd.management.pojo.Board;
import com.lyd.management.pojo.Food;
import com.lyd.management.pojo.Room;
import com.lyd.management.service.BoardService;
import com.lyd.management.service.FoodService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/board")
public class BoardController {
    @Autowired
    private BoardService boardService;


    @SaIgnore
    @GetMapping("/page")
    public SaResult getList(int page, int pageSize){
        //构造分页构造器
        Page<Board> pageInfo = new Page<>(page, pageSize);
        //构造条件构造器
        LambdaQueryWrapper<Board> queryWrapper = new LambdaQueryWrapper<>();
//        //添加排序条件
//        queryWrapper.orderByDesc(Food::getUpdateTime);
        //执行查询
        boardService.page(pageInfo, queryWrapper);
        return SaResult.data(pageInfo);
    }


    @SaIgnore
    @PostMapping("/add")
    public SaResult add(@RequestBody Board board){
        if(boardService.save(board)) {
            return SaResult.ok("新增成功");
        }else{
            return SaResult.error("新增失败");
        }
    }


}
